#include<vector>
using namespace std;

class Solution {
    vector<vector<int>>ops = { {-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1} };

    int getLives(vector<vector<int>>& board, int row, int col) {
        int ans = 0;
        for (int i = 0; i < ops.size(); ++i) {
            if (row + ops[i][0] < 0 || row + ops[i][0] >= board.size() ||
                col + ops[i][1] < 0 || col + ops[i][1] >= board[row].size())
                continue;
            ans += board[row+ ops[i][0]][col+ ops[i][1]];
        }
        return ans;
    }

public:
    void gameOfLife(vector<vector<int>>& board) {
        vector<vector<int>> bd = board;
        for (int i = 0; i < bd.size(); ++i) {
            for (int j = 0; j < bd[i].size(); ++j) {
                int ans = getLives(bd, i, j);
                if (bd[i][j]) {
                    if (ans < 2 || ans > 3) board[i][j] = 0;
                }
                else if (ans == 3) 
                    board[i][j] = 1;
            }
        }
    }
};

int main() {
    Solution sol;
    vector<vector<int>> board = { {0,1,0},{0,0,1},{1,1,1},{0,0,0} };
    sol.gameOfLife(board);

}